#include <bits/stdc++.h>

#define ll long long
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
const int INF = 1e9;
using namespace std;
/*思考区
最小值一定是1所以只需要删到只剩最后一个数字
删除次数ans=末尾0的个数+之后的非0数字个数
*/
void solve() {
    int ans=0; 
    string num;
    cin >> num;
    int n = num.size();
    for (int i = n - 1; i >= 0; i--) {//末尾0的个数
        if (num[i] == '0') {
            ans++;
        }
        else {
            break;
        }
    }
    int temp = ans;
    for (int i = n-temp-2; i >= 0; i--) {//
        if (num[i] == '0') {
            continue;
        }
        else {
            ans++;
        }
    }
    cout << ans<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 0;
    cin >> t;
    while (t--)
        solve();
    return 0;
}